<template>
	<div>
		<el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="80px">
			<el-form-item label="抹零设置" prop="zeroStatus">
				<el-radio-group @change="wipeStatus" v-model="dataForm.zeroStatus">
					<el-radio label="1">抹零</el-radio>
					<el-radio label="2">不抹零</el-radio>
				</el-radio-group>
			</el-form-item>
			<div v-show="dataForm.zeroStatus === '1'">
				<el-form-item label="抹零规则">
					<el-radio v-model="dataForm.rule" label="1">
						四舍五入到元
						<span style="color: red;">（例如：5.10 -> 5.00）</span>
					</el-radio>
					<el-radio v-model="dataForm.rule" label="2">
						向下抹零到元
						<span style="color: red;">（例如：5.80 -> 5.00）</span>
					</el-radio>
					<el-radio v-model="dataForm.rule" label="3">
						向上抹零到元
						<span style="color: red;">（例如：5.30 -> 6.00）</span>
					</el-radio>
				</el-form-item>
				<el-form-item label="">
					<el-radio v-model="dataForm.rule" label="4">
						四舍五入到角
						<span style="color: red;">（例如：5.28 -> 5.30）</span>
					</el-radio>
					<el-radio v-model="dataForm.rule" label="5">
						向下抹零到角
						<span style="color: red;">（例如：5.12 -> 5.10）</span>
					</el-radio>
					<el-radio v-model="dataForm.rule" label="6">
						向上抹零到角
						<span style="color: red;">（例如：5.12 -> 5.20）</span>
					</el-radio>
				</el-form-item>
			</div>
		</el-form>
		<div align="center" slot="footer" class="dialog-footer"><el-button type="primary" @click="dataFormSubmit()" :disabled="disabledSubmit">确定</el-button></div>
	</div>
</template>

<script>
export default {
	components:{

	},

	data() {
		return {
			ruleVisle: true,
			dataForm: {
				id:'',
				zeroStatus: '1',
				rule: null
			}
		};
	},

	created() {
		this.getWipeRule()
	},

	methods: {
		wipeStatus() {
			if (this.dataForm.zeroStatus === '1') {
				this.dataForm.zeroStatus === '1'
			} else {
				this.dataForm.zeroStatus === '2'
				this.dataForm.rule = null;
			}
		},

		getWipeRule() {
			this.$http({
				url: this.$http.adornUrl(`/store/tstorewipezerorule/info`),
				method: 'get',
				params: this.$http.adornParams()
			}).then(({ data }) => {
				if (data && data.code === 0) {
					this.dataForm.id = data.tStoreWipeZeroRule.id;
					this.dataForm.zeroStatus = data.tStoreWipeZeroRule.zeroStatus.toString();
					this.dataForm.rule = data.tStoreWipeZeroRule.rule.toString();
				}
			});
		},

		// 表单提交
		dataFormSubmit() {
			if(this.dataForm.rule === null){
				this.dataForm.rule = null
			}
			this.$http({
				url: this.$http.adornUrl(`/store/tstorewipezerorule/save`),
				method: 'post',
				data: this.$http.adornData({
					zeroStatus: this.dataForm.zeroStatus,
					rule: this.dataForm.rule,
					id:this.dataForm.id
				})
			}).then(({ data }) => {
				if (data && data.code === 0) {
					this.$message({
						message: '设置抹零后需要重新登录系统才能生效',
						type: 'success',
						duration: 1500,
						onClose: () => {
							this.visible = false;
							this.$emit('refreshDataList');
						}
					});
				} else {
					this.$message.error(data.msg);
				}
			});
		}
	}
};
</script>
